package org.base;

import java.util.List;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;

@Named(value = "barrioController")
@ViewScoped
public class BarrioController extends AbstractController<Barrio> {

    @Inject
    private PartidoController partidoIdController;
    @Inject
    private NomenclaturaCatastralController nomenclaturaOrigenIdController;
    @Inject
    private DatoDelDominioController datoDelDominioIdController;
    @Inject
    private ExpedienteController expedienteCollectionController;

    private List<Barrio> items;
    
    
     @Override
    public List<Barrio> getItems() {
       if (items == null) {
            items = (List<Barrio>)ejbFacade.findAll();
        }
        return items;
    }

    public void setItems(List<Barrio> items) {
        this.items = items;
    }
    
    public BarrioController() {
        // Inform the Abstract parent controller of the concrete Barrio?cap_first Entity
        super(Barrio.class);
    }

    /**
     * Resets the "selected" attribute of any parent Entity controllers.
     */
    public void resetParents() {
        partidoIdController.setSelected(null);
        nomenclaturaOrigenIdController.setSelected(null);
        datoDelDominioIdController.setSelected(null);
    }

    /**
     * Sets the "selected" attribute of the Partido controller in order to
     * display its data in a dialog. This is reusing existing the existing View
     * dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void preparePartidoId(ActionEvent event) {
        if (this.getSelected() != null && partidoIdController.getSelected() == null) {
            partidoIdController.setSelected(this.getSelected().getPartidoId());
        }
    }

    /**
     * Sets the "selected" attribute of the NomenclaturaCatastral controller in
     * order to display its data in a dialog. This is reusing existing the
     * existing View dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void prepareNomenclaturaOrigenId(ActionEvent event) {
        if (this.getSelected() != null && nomenclaturaOrigenIdController.getSelected() == null) {
            nomenclaturaOrigenIdController.setSelected(this.getSelected().getNomenclaturaOrigenId());
        }
    }

    /**
     * Sets the "selected" attribute of the DatoDelDominio controller in order
     * to display its data in a dialog. This is reusing existing the existing
     * View dialog.
     *
     * @param event Event object for the widget that triggered an action
     */
    public void prepareDatoDelDominioId(ActionEvent event) {
        if (this.getSelected() != null && datoDelDominioIdController.getSelected() == null) {
            datoDelDominioIdController.setSelected(this.getSelected().getDatoDelDominioId());
        }
    }

    /**
     * Sets the "items" attribute with a collection of Expediente entities that
     * are retrieved from Barrio?cap_first and returns the navigation outcome.
     *
     * @return navigation outcome for Expediente page
     */
    public String navigateExpedienteCollection() {
        if (this.getSelected() != null) {
            FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("Expediente_items", this.getSelected().getExpedienteCollection());
        }
        return "/expediente/index";
    }

}
